﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace WPFSample.MeasureSample
{
    class MyPanel : Panel
    {
        protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize)
        {
            foreach (UIElement item in this.InternalChildren)
            {
                item.Measure(availableSize);
            }
            return availableSize;//MyPanel 返回它期望的大小
        }

        protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize)
        {
            double xCordinate = 0;
            foreach (UIElement item in this.InternalChildren)
            {
                item.Arrange(new Rect(new Point(xCordinate, 0), item.DesiredSize));
                xCordinate += item.DesiredSize.Width;
            }
            return finalSize;
        }
    }
}
